import time
# from usart_stm32.usart import get_car_data, send_car_data
from server_api import get_work, post_order_state, has_work, post_temp_hum, post_point, post_warning, get_control
from calculate.car_operator import Operate
from calculate.car_direction import pos_to_direction, is_arrive


server = 'http://106.53.119.46'
car_id = 1
car_pt = '113.08383,28.321184'  # 从stm32获取

oid = None
i_time = None
i_temp = '666'
i_hum = '555'
warning_flag = '0'
complete_flag = False

control_flag = False


# def get_car_control():
#     global control_flag
#     data = get_control(server, car_id)
#     if data is None:
#         return
#     control_flag = True
#     send_car_data(data)


def data_cleaning(int_temp, int_hum, int_warning_flag):
    if int_temp < 5 or int_temp > 50 or int_hum < 20 or int_hum > 100 or (int_warning_flag != 0 and int_warning_flag != 1 and int_warning_flag != 2):
        return True  # 有异常,需跳过
    return False  # 无异常

# 测试从服务器获取的经纬度并发送给小车
if __name__ == '__main__':
    while True:
        if not has_work(server):
            time.sleep(0.5)
            continue

        get_task_flag, oid, paths = get_work(server, car_pt, car_id, i_temp, i_hum)

        data_send_to = "$OK,"

        for key in paths.keys():
            for pt in paths[key]:
                data_send_to += str(pt[1]) + ',' + str(pt[0]) + ','

        print(data_send_to)
        break

        # print(f"data: {data}")
        # send_car_data(data_send_to)
        # print(f"发送完毕")
        

    

        

    






    


